﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;

namespace THO7AlgoritmTimerApplication
{
    class BlackenAlgorithm : VisionAlgorithm
    {
        public BlackenAlgorithm(String name) : base(name) { }
       
        
        public override System.Drawing.Bitmap DoAlgorithm(System.Drawing.Bitmap sourceImage)
        {
            
            Rectangle rect = new Rectangle(0, 0, sourceImage.Width, sourceImage.Height);
            Bitmap returnImage = (Bitmap) sourceImage.Clone();
            BitmapData srcData = returnImage.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

            
           

            int stride = srcData.Stride;
            int nOffset = stride - sourceImage.Width * 3;
            System.IntPtr Scan0 = srcData.Scan0;


            unsafe
            {
                byte* p = (byte*)(void*)Scan0;
                for (int y = 0; y < sourceImage.Height; ++y)
                {
                    for (int x = 0; x < sourceImage.Width; ++x)
                    {

                        p[0] = (byte) 0;
                        p[1] = (byte) 0;
                        p[2] = (byte) 0;

                        p += 3;
                        
                        
                    }
                   
                    p += nOffset;
                  
                }
            }
            returnImage.UnlockBits(srcData);
            return returnImage;
        }
    }
}